package com.stone.cat.common.util;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by stone on 2017/9/17.
 */
public final class MapUtil {

	/**
	 * @param t
	 * @param <T>
	 * @return
	 */
	public static <T> Map<String, String> objectToMap(T t) {
		Map<String, String> map = new HashMap<>(10);
		final Class<?> clazz = t.getClass();
		final Field[] fields = clazz.getDeclaredFields();
		for (Field field : fields) {
			try {
				field.setAccessible(true);
				final String name = field.getName();
				final String value = field.get(t) + "";
				map.put(name, value);
			} catch (IllegalAccessException e) {
				continue;
			}
		}
		return map;
	}
}
